﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XMK.Tadong.Biz;
using System.Configuration;
using HU8.Helpers.Files;
using System.Data;
using System.IO;
using HU8.Web.FileExplorer;

namespace XMK.Tadong.Web.WebFileExplorer.UnauditedData
{
    public partial class MoveFile : FileExplorerPage
    {
        #region 事件处理程序

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                initData();
            }
        }

        protected void btnAudit_Click(object sender, EventArgs e)
        {
            TB_TEAM_FILEBiz bll = new TB_TEAM_FILEBiz();
            string File_ID = this.Request.QueryString["File_ID"];

            DataTable dt = bll.GetModel(File_ID);
            if (dt.Rows.Count > 0)
            {
                //将文件复制到相应的课题组待审核的文件夹下
                string Path = ConfigurationManager.AppSettings["DiskPath"];

                string Svae_Path = Path + dt.Rows[0]["Save_Path"].ToString().ToString();

                string newPath = "/已审核";// Path + "Group/" + dt.Rows[0]["Team_ID"].ToString() + "/已审核";

                newPath = newPath.Replace(@"\", "/");

                string NewSaveSath = newPath.Replace(Path, "");

                string FILE_NAME = dt.Rows[0]["FILE_NAME"].ToString();
                string[] filename = FILE_NAME.Split('.');
                if (bll.AuditData(File_ID, NewSaveSath))
                {

                    //1、原文件
                    string oidPath = Svae_Path + "/" + FILE_NAME;
                    FileHelper.Cut(oidPath, newPath);
                    //2、pdf文件
                    string pdfPath = Svae_Path + "/" + filename[0].ToString() + ".pdf";
                    FileHelper.Cut(pdfPath, newPath);
                    //3、swf文件
                    string swfPath = Svae_Path + "/" + filename[0].ToString() + ".swf";
                    FileHelper.Cut(swfPath, newPath);

                    lblErr.Text = lang.Get("SPACE_Audit_Success");// "审核成功";
                    Response.Write("<script type='text/javascript'>$(this).wijdialog('close');</script>");
                }
            }


           
        }


        #endregion 事件处理程序

        #region 函数集

        public void initData()
        {
             TB_TEAM_FILEBiz bll = new TB_TEAM_FILEBiz();
            string File_ID = this.Request.QueryString["File_ID"];

            DataTable dt = bll.GetModel(File_ID);
            if (dt.Rows.Count > 0)
            {
                //将文件复制到相应的课题组待审核的文件夹下
                string Path = ConfigurationManager.AppSettings["DiskPath"];
                string Svae_Path = Path + dt.Rows[0]["Save_Path"].ToString().ToString();
                //获取子文件夹
                string[] files = System.IO.Directory.GetDirectories(Path + "Group/" + dt.Rows[0]["Team_ID"].ToString());
                this.RadioButtonList1.DataSource = files;
                this.RadioButtonList1.DataBind();
                string pathss = GetFoldAll(Path, "DropName", "tplPath");
            }
        }

        #endregion 函数集

        #region 获取指定文件夹下所有子目录及文件(树形) 
       
        /**************************************** 
         * 函数名称：GetFoldAll(string Path) 
         * 功能说明：获取指定文件夹下所有子目录及文件(下拉框形) 
         * 参    数：Path:详细路径 
         * 调用示列： 
         *            string strDirlist = Server.MapPath("templates");       
         *            this.Literal2.Text = EC.FileObj.GetFoldAll(strDirlist,"tpl",""); 
        *****************************************/ 
        /// <summary> 
        /// 获取指定文件夹下所有子目录及文件(下拉框形) 
        /// </summary> 
        /// <param name="Path">详细路径</param> 
        ///<param name="DropName">下拉列表名称</param> 
        ///<param name="tplPath">默认选择模板名称</param> 
       // public static string GetFoldAll(string Path,string DropName,string tplPath) 
        public  string GetFoldAll(string Path,string DropName,string tplPath) 
        {

            string strDrop = "<select name=\"" + DropName + "\" id=\"" + DropName + "\"><option value=\"\">" + "--" + lang.Get("") + "--"+"</option>"; //--请选择详细模板--</option>"; 
            string str = ""; 
            DirectoryInfo thisOne = new DirectoryInfo(Path); 
            str = ListTreeShow(thisOne, 0, str,tplPath); 
            return strDrop+str+"</select>"; 

        } 

        /// <summary> 
        /// 获取指定文件夹下所有子目录及文件函数 
        /// </summary> 
        /// <param name="theDir">指定目录</param> 
        /// <param name="nLevel">默认起始值,调用时,一般为0</param> 
        /// <param name="Rn">用于迭加的传入值,一般为空</param> 
        /// <param name="tplPath">默认选择模板名称</param> 
        /// <returns></returns> 
        public static string ListTreeShow(DirectoryInfo theDir, int nLevel, string Rn,string tplPath)//递归目录 文件 
        { 
            DirectoryInfo[] subDirectories = theDir.GetDirectories();//获得目录 

            foreach (DirectoryInfo dirinfo in subDirectories) 
            { 

                Rn += "<option value=\"" + dirinfo.Name.ToString() + "\""; 
                if (tplPath.ToLower() == dirinfo.Name.ToString().ToLower()) 
                { 
                    Rn += " selected "; 
                } 
                Rn += ">"; 

                if (nLevel == 0) 
                { 
                    Rn += "┣"; 
                } 
                else 
                { 
                    string _s = ""; 
                    for (int i = 1; i <= nLevel; i++) 
                    { 
                        _s += "│ "; 
                    } 
                    Rn += _s + "┣"; 
                } 
                Rn += "" + dirinfo.Name.ToString() + "</option>"; 

                Rn = ListTreeShow(dirinfo, nLevel + 1, Rn, tplPath); 


            } 
            return Rn; 
        } 
        #endregion 

    }
}